﻿using System;
using System.Globalization;
using System.Windows.Data;
using System.Windows.Media;

namespace DACU.Tools.Converters
{
	class BoolToColor:IValueConverter
	{
		private readonly Color _yes = Color.FromArgb(255, 134, 234, 146);
		private readonly Color _no = Color.FromArgb(255, 234, 148, 144);
		private readonly Color _unknown = Color.FromArgb(255,0,0,0);

		public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
		{
			Color color = value != null && value is bool ? ((bool) value ? _yes : _no) : _unknown;
			return new SolidColorBrush(color);
		}

		public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
		{
			if (value == null || !(value is SolidColorBrush)) return false;
			return ((SolidColorBrush)value).Color == _yes;
		}
	}
}
